{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-04-08T14:41:48.028039Z",
     "start_time": "2025-04-08T14:41:48.024355Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1 2 3]\n",
      "int64\n",
      "(3,)\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "\n",
    "a = np.array([1,2,3])\n",
    "# 【1 2 3】\n",
    "print(a)\n",
    "# 数组元素的数据类型\n",
    "print(a.dtype)\n",
    "# 数组形状\n",
    "\n",
    "print(a.shape) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-04-08T14:45:21.696357Z",
     "start_time": "2025-04-08T14:45:21.422327Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Python 列表相加耗时: 0.07969999313354492\n",
      "NumPy 数组相加耗时: 0.0037021636962890625\n"
     ]
    }
   ],
   "source": [
    "# 比较Numpy和Python列表的运算速度\n",
    "\n",
    "import numpy as np\n",
    "import time\n",
    "\n",
    "size = 10**6 #100万个元素\n",
    "list1 = list(range(size))\n",
    "list2 = list(range(size))\n",
    "\n",
    "arr1 = np.array(list1)\n",
    "arr2 = np.array(list2)\n",
    "\n",
    "# python列表计算\n",
    "start_time = time.time()\n",
    "result_list = [x + y for x,y in zip(list1,list2)]\n",
    "\n",
    "print(\"Python 列表相加耗时:\", time.time() - start_time)\n",
    "\n",
    "# NumPy 数组计算\n",
    "start_time = time.time()\n",
    "result_array = arr1 + arr2\n",
    "print(\"NumPy 数组相加耗时:\", time.time() - start_time)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
